#pragma once
#ifndef CGAME_H
#define CGAME_H
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Input.h"
#include "Sprite.h"
#include "Resources.h"
#include <vector>
#include <fstream>
#include <iostream>

#include "MenuState.h"
#include "PlayState.h"
#include "OptionState.h"
#include "AboutState.h"
using namespace std;

#define KEYBOARD_BUFFER_SIZE 1024

extern bool	_onSound;
extern bool _onMusic;

class Game
{
private:
	LPDIRECT3D9					_pd3d;
	LPDIRECT3DDEVICE9			_pd3ddv;
	LPDIRECT3DSURFACE9			_back_buffer;
	LPD3DXSPRITE				_sprite_handler;

	DWORD						_delta_time;
	DWORD						_last_time;
	int							_is_full_screen;
	int							_frame_rate;

	int							_screen_width;
	int							_screen_height;

	int							_viewport_width;
	int							_viewport_height;

	HINSTANCE					_hInstance;
	HWND						_hWnd;
	LPSTR						_name;

	Input*						_input;

	static LRESULT CALLBACK _WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM);

	bool _InitWindow();
	bool _InitDirectX();

	void _UpdateWorld(float delta);
	void _RenderFrame();
	void _LoadResources();

	//=========================================================================================================//
	State* _state;
	void ChangeState();

public:
	Game(HINSTANCE hInstance, LPSTR name, int screenwidth, int screenheight, int isfullscreen, int framerate);
	~Game();

	LPDIRECT3D9 GetDirectX() { return _pd3d; }
	LPDIRECT3DDEVICE9 GetDevice() { return _pd3ddv; }
	LPDIRECT3DSURFACE9 GetBackBuffer() { return _back_buffer; }

	int GetScreenWidth() { return _screen_width; }
	int GetScreenHeight() { return _screen_height; }

	bool Init();
	void Run();

	// Game
	Resources*		_resources;
};
#endif
